package com.huatai.datacenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.datacenter.entity.datamodel.MappingModelFieldEntity;
import com.huatai.datacenter.mapper.MappingModelFieldMapper;
import com.huatai.datacenter.service.MappingModelFieldService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 映射模型字段服务实现类
 *
 * @author lizhong
 */
@Service
public class MappingModelFieldServiceImpl extends ServiceImpl<MappingModelFieldMapper, MappingModelFieldEntity> implements MappingModelFieldService {

	/**
	 * 根据映射模型id查询字段
	 *
	 * @param mappingModelId 映射模型id
	 * @return 该映射模型的字段列表
	 */
	public List<MappingModelFieldEntity> getMappingModelFieldList(Long mappingModelId) {
		LambdaQueryWrapper<MappingModelFieldEntity> fieldQuery = Wrappers.lambdaQuery();

		// 先排除已删除的，按创建时间排序
		fieldQuery
			.eq(MappingModelFieldEntity::getDeleted, false)
			.eq(MappingModelFieldEntity::getMappingModelId, mappingModelId)
			.orderByAsc(MappingModelFieldEntity::getCreateTime);
		return list(fieldQuery);
	}
}
